index.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { useParams } from 'common'
  2. import { useRouter } from 'next/router'
  3. import { useEffect } from 'react'
  4. import { useUnifiedLogsPreview } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
  5. import { UnifiedLogs } from '@/components/interfaces/UnifiedLogs/UnifiedLogs'
  6. import DefaultLayout from '@/components/layouts/DefaultLayout'
  7. import { ProjectLayout } from '@/components/layouts/ProjectLayout'
  8. import { UnknownInterface } from '@/components/ui/UnknownInterface'
  9. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  10. import type { NextPageWithLayout } from '@/types'
  11. export const LogPage: NextPageWithLayout = () => {
  12. const router = useRouter()
  13. const { ref } = useParams()
  14. const logsEnabled = useIsFeatureEnabled('logs:all')
  15. const { isEnabled: isUnifiedLogsEnabled, isLoading } = useUnifiedLogsPreview()
  16. useEffect(() => {
  17. if (logsEnabled && !isLoading && !isUnifiedLogsEnabled && ref) {
  18. router.replace(`/project/${ref}/logs/explorer`)
  19. }
  20. // eslint-disable-next-line react-hooks/exhaustive-deps
  21. }, [logsEnabled, isLoading, isUnifiedLogsEnabled, ref])
  22. if (!logsEnabled) {
  23. return (
  24. <DefaultLayout>
  25. <ProjectLayout browserTitle={{ section: 'logs' }}>
  26. <UnknownInterface urlBack={`/project/${ref}`} />
  27. </ProjectLayout>
  28. </DefaultLayout>
  29. )
  30. }
  31. if (isUnifiedLogsEnabled) {
  32. return (
  33. <DefaultLayout>
  34. {/* Omit the generic product segment here; project/org context already makes the route clear. */}
  35. <ProjectLayout browserTitle={{ section: 'unified logs' }}>
  36. <UnifiedLogs />
  37. </ProjectLayout>
  38. </DefaultLayout>
  39. )
  40. }
  41. return null
  42. }
  43. // Don't use getLayout since we're handling layouts conditionally within the component
  44. LogPage.getLayout = (page) => page
  45. export default LogPage